<template>
  <div class="dashboard-container">
    <el-form ref="ruleForm" :model="form" :rules="rules" label-width="100px" class="demo-ruleForm">
      <el-form-item label="标语文字" prop="slogan">
        <el-input v-model="form.slogan" />
      </el-form-item>
      <el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
        </el-form-item>
      </el-form-item></el-form>
  </div>

</template>

<script>
import { getSloganApi, uploadSloganApi } from '@/api/main'
export default {
  data() {
    return {
      form: {
        slogan: ''
      },
      rules: {
        slogan: [
          { required: true, message: '请输入slogan', trigger: 'blur' }
        ]
      }
    }
  },
  created() {
    this.getSlogan()
  },
  methods: {
    getSlogan() {
      getSloganApi().then(res => {
        this.form.slogan = res.slogan
      })
    },
    submitForm(formname) {
      this.$refs[formname].validate((valid) => {
        if (valid) {
          const data = {
            slogan: this.form.slogan
          }
          uploadSloganApi(data).then(res => {
            if (res.code === 200) {
              this.$message.success(res.msg)
            }
          })
        } else {
          this.$message.error('信息提交失败，请填写内容后提交！')
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.dashboard {
    &-container {
        margin: 30px;
    }
    &-text {
        font-size: 30px;
        line-height: 46px;
    }
}
</style>
